package com.gdth.bank.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gdth.bank.R;
import com.gdth.bank.adapter.JtcyXxbListAdapter.OnJtcyXxDetailClickListener;
import com.gdth.bank.adapter.JtcyXxbListAdapter.ViewHolder;
import com.gdth.bank.model.DjjjdjItem;
import com.gdth.model.ImageItem;

public class GmJjDjJjRrAdapter extends BaseAdapter{
private LayoutInflater mInflater;
	
	private Context context;
	
	private List<DjjjdjItem> mData;
	
	public GmJjDjJjRrAdapter(Context context, List<DjjjdjItem> mData) {
	    this.mInflater = LayoutInflater.from(context);
	    this.context = context;
	    this.mData = mData;
    }
	
	public int getCount() {
		// TODO Auto-generated method stub
		return this.mData.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.mData.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		DjjjdjItem model = mData.get(position);
		final int number = position;
		ViewHolder holder;
        //观察convertView随ListView滚动情况            
        if (convertView == null) {
        	convertView = mInflater.inflate(R.layout.item_jtcyxxb_listview, null);
        	holder = new ViewHolder();
        	/*得到各个控件的对象*/                    
        	holder.txt_xm = (TextView) convertView.findViewById(R.id.jtcyxm_item_val);
        	holder.txt_val = (TextView) convertView.findViewById(R.id.jtcyzjh_item_val);
        	holder.txt_dj = (TextView) convertView.findViewById(R.id.jtcydj_item_detail);
        	if(this.mOnJtcyXxDetailClickListener !=null){
        		holder.txt_dj.setOnClickListener(new  OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						mOnJtcyXxDetailClickListener.clickListener(number);
					}
				});
        	}
        	
        	convertView.setTag(holder);//绑定ViewHolder对象                   
    	}else{
            holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象                  
        }

        holder.txt_val.setText(model.getValue());
        holder.txt_xm.setText(model.getImg());
        holder.txt_dj.setText(model.getGnlj());
      
        return convertView;
	}
	
	public final class ViewHolder{
		public TextView txt_xm;
		public TextView txt_val;
		public TextView txt_dj;
    }
	
	private OnJtcyXxDetailClickListener mOnJtcyXxDetailClickListener;
	
	public void setmOnJtcyXxDetailClickListener(
			OnJtcyXxDetailClickListener mOnJtcyXxDetailClickListener) {
		this.mOnJtcyXxDetailClickListener = mOnJtcyXxDetailClickListener;
	}

	public interface OnJtcyXxDetailClickListener {
		void clickListener(int position);
	}
}
